#include<bits/stdc++.h>
using namespace std;

struct node {
    string id, fa, ma;
    string sex;
} a[100005];

unordered_map<string, int> mp;

int n;

set<string> st;
void dfs(string x, int gen) {
    if(x == "-1")	return ;
    if(gen > 5)	return ;

    st.insert(x);

    dfs(a[mp[x]].fa, gen + 1);
    dfs(a[mp[x]].ma, gen + 1);
}

void chkDfs(string y, int gen, bool &flag) {
    if(flag)	return ;
    if(y == "-1")	return ;
    if(gen > 5)	return ;

    if(st.count(y)) {
        flag = 1;
        return ;
    }

    chkDfs(a[mp[y]].fa, gen + 1, flag);
    chkDfs(a[mp[y]].ma, gen + 1, flag);
}

signed main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].id >> a[i].sex >> a[i].fa >> a[i].ma;
        mp[a[i].id] = i;
    }
    int num = n;
    for(int i = 1; i <= n; i++) {
        if(!mp.count(a[i].fa)) {
            mp[a[i].fa] = ++num;
            a[num] = {a[i].fa, "-1", "-1", "M"};
        }
        if(!mp.count(a[i].ma)) {
            mp[a[i].ma] = ++num;
            a[num] = {a[i].ma, "-1", "-1", "F"};
        }
    }

    int k;
    cin >> k;
    for(int i = 1; i <= k; i++) {
        string x, y;
        cin >> x >> y;

        if(a[mp[x]].sex == a[mp[y]].sex)
            cout << "Never Mind";
        else {
            st.clear();

            dfs(x, 1);

            bool flag = 0;
            chkDfs(y, 1, flag);

            if(flag)
                cout << "No";
            else
                cout << "Yes";
        }
        cout << "\n";
    }
    return 0;
}

